from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

op = webdriver.ChromeOptions()
op.add_experimental_option('excludeSwitches', ['enable-automation'])
op.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=op)

driver.get("http://118.121.200.162:8085/index")
sleep(2)

driver.find_element(By.CSS_SELECTOR,"#navbar > div > ul > li:nth-child(1) > a").click()
sleep(3)

driver.find_element(By.CSS_SELECTOR,"#userID").send_keys("hs")
sleep(1)
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("hs020512")
sleep(1)
driver.find_element(By.CSS_SELECTOR,"#submit").click()
sleep(1)

alert = driver.switch_to.alert.accept()
sleep(2)

name = driver.find_element(By.CSS_SELECTOR,"#navbar > div > ul > li:nth-child(1) > a > p")
name1 = name.text
print(name1)

assert "hs" in name1
cookieList = driver.get_cookies()

driver.quit()
driver = webdriver.Chrome(options=op)

driver.get("http://118.121.200.162:8085/index")
sleep(2)
for i in cookieList:
    driver.add_cookie(i)
driver.refresh()
sleep(2)

driver.quit()
